

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="Description" content="scikit-learn: machine learning in Python">

  
  <title>2.2. Manifold learning &mdash; scikit-learn 0.22 documentation</title>
  
  <link rel="canonical" href="http://scikit-learn.org/stable/modules/manifold.html" />

  
  <link rel="shortcut icon" href="../_static/favicon.ico"/>
  

  <link rel="stylesheet" href="../_static/css/vendor/bootstrap.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/gallery.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script> 
</head>
<body>
<nav id="navbar" class="sk-docs-navbar navbar navbar-expand-md navbar-light bg-light py-0">
  <div class="container-fluid sk-docs-container px-0">
      <a class="navbar-brand py-0" href="../index.html">
        <img
          class="sk-brand-img"
          src="../_static/scikit-learn-logo-small.png"
          alt="logo"/>
      </a>
    <button
      id="sk-navbar-toggler"
      class="navbar-toggler"
      type="button"
      data-toggle="collapse"
      data-target="#navbarSupportedContent"
      aria-controls="navbarSupportedContent"
      aria-expanded="false"
      aria-label="Toggle navigation"
    >
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="sk-navbar-collapse collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="../install.html">Install</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="../user_guide.html">User Guide</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="classes.html">API</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="../auto_examples/index.html">Examples</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../getting_started.html">Getting Started</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../tutorial/index.html">Tutorial</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../glossary.html">Glossary</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../developers/index.html">Development</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../faq.html">FAQ</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../related_projects.html">Related packages</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../roadmap.html">Roadmap</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../about.html">About us</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="https://github.com/scikit-learn/scikit-learn">GitHub</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="https://scikit-learn.org/dev/versions.html">Other Versions</a>
        </li>
        <li class="nav-item dropdown nav-more-item-dropdown">
          <a class="sk-nav-link nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">More</a>
          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
              <a class="sk-nav-dropdown-item dropdown-item" href="../getting_started.html">Getting Started</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../tutorial/index.html">Tutorial</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../glossary.html">Glossary</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../developers/index.html">Development</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../faq.html">FAQ</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../related_projects.html">Related packages</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../roadmap.html">Roadmap</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../about.html">About us</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="https://github.com/scikit-learn/scikit-learn">GitHub</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="https://scikit-learn.org/dev/versions.html">Other Versions</a>
          </div>
        </li>
      </ul>
      <div id="searchbox" role="search">
          <div class="searchformwrapper">
          <form class="search" action="../search.html" method="get">
            <input class="sk-search-text-input" type="text" name="q" aria-labelledby="searchlabel" />
            <input class="sk-search-text-btn" type="submit" value="Go" />
          </form>
          </div>
      </div>
    </div>
  </div>
</nav>
<div class="d-flex" id="sk-doc-wrapper">
    <input type="checkbox" name="sk-toggle-checkbox" id="sk-toggle-checkbox">
    <label id="sk-sidemenu-toggle" class="sk-btn-toggle-toc btn sk-btn-primary" for="sk-toggle-checkbox">Toggle Menu</label>
    <div id="sk-sidebar-wrapper" class="border-right">
      <div class="sk-sidebar-toc-wrapper">
        <div class="sk-sidebar-toc-logo">
          <a href="../index.html">
            <img
              class="sk-brand-img"
              src="../_static/scikit-learn-logo-small.png"
              alt="logo"/>
          </a>
        </div>
        <div class="btn-group w-100 mb-2" role="group" aria-label="rellinks">
            <a href="mixture.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="2.1. Gaussian mixture models">Prev</a><a href="../unsupervised_learning.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="2. Unsupervised learning">Up</a>
            <a href="clustering.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="2.3. Clustering">Next</a>
        </div>
        <div class="alert alert-danger p-1 mb-2" role="alert">
          <p class="text-center mb-0">
          <strong>scikit-learn 0.22</strong><br/>
          <a href="http://scikit-learn.org/dev/versions.html">Other versions</a>
          </p>
        </div>
        <div class="alert alert-warning p-1 mb-2" role="alert">
          <p class="text-center mb-0">
            Please <a class="font-weight-bold" href="../about.html#citing-scikit-learn"><string>cite us</string></a> if you use the software.
          </p>
        </div>
          <div class="sk-sidebar-toc">
            <ul>
<li><a class="reference internal" href="#">2.2. Manifold learning</a><ul>
<li><a class="reference internal" href="#introduction">2.2.1. Introduction</a></li>
<li><a class="reference internal" href="#isomap">2.2.2. Isomap</a><ul>
<li><a class="reference internal" href="#complexity">2.2.2.1. Complexity</a></li>
</ul>
</li>
<li><a class="reference internal" href="#locally-linear-embedding">2.2.3. Locally Linear Embedding</a><ul>
<li><a class="reference internal" href="#id3">2.2.3.1. Complexity</a></li>
</ul>
</li>
<li><a class="reference internal" href="#modified-locally-linear-embedding">2.2.4. Modified Locally Linear Embedding</a><ul>
<li><a class="reference internal" href="#id4">2.2.4.1. Complexity</a></li>
</ul>
</li>
<li><a class="reference internal" href="#hessian-eigenmapping">2.2.5. Hessian Eigenmapping</a><ul>
<li><a class="reference internal" href="#id5">2.2.5.1. Complexity</a></li>
</ul>
</li>
<li><a class="reference internal" href="#spectral-embedding">2.2.6. Spectral Embedding</a><ul>
<li><a class="reference internal" href="#id7">2.2.6.1. Complexity</a></li>
</ul>
</li>
<li><a class="reference internal" href="#local-tangent-space-alignment">2.2.7. Local Tangent Space Alignment</a><ul>
<li><a class="reference internal" href="#id8">2.2.7.1. Complexity</a></li>
</ul>
</li>
<li><a class="reference internal" href="#multi-dimensional-scaling-mds">2.2.8. Multi-dimensional Scaling (MDS)</a><ul>
<li><a class="reference internal" href="#metric-mds">2.2.8.1. Metric MDS</a></li>
<li><a class="reference internal" href="#nonmetric-mds">2.2.8.2. Nonmetric MDS</a></li>
</ul>
</li>
<li><a class="reference internal" href="#t-distributed-stochastic-neighbor-embedding-t-sne">2.2.9. t-distributed Stochastic Neighbor Embedding (t-SNE)</a><ul>
<li><a class="reference internal" href="#optimizing-t-sne">2.2.9.1. Optimizing t-SNE</a></li>
<li><a class="reference internal" href="#barnes-hut-t-sne">2.2.9.2. Barnes-Hut t-SNE</a></li>
</ul>
</li>
<li><a class="reference internal" href="#tips-on-practical-use">2.2.10. Tips on practical use</a></li>
</ul>
</li>
</ul>

          </div>
      </div>
    </div>
    <div id="sk-page-content-wrapper">
      <div class="sk-page-content container-fluid body px-md-3" role="main">
        
  <div class="section" id="manifold-learning">
<span id="manifold"></span><h1>2.2. Manifold learning<a class="headerlink" href="#manifold-learning" title="Permalink to this headline">¶</a></h1>
<div class="quote line-block">
<div class="line">Look for the bare necessities</div>
<div class="line">The simple bare necessities</div>
<div class="line">Forget about your worries and your strife</div>
<div class="line">I mean the bare necessities</div>
<div class="line">Old Mother Nature’s recipes</div>
<div class="line">That bring the bare necessities of life</div>
<div class="line"><br /></div>
<div class="line-block">
<div class="line">– Baloo’s song [The Jungle Book]</div>
</div>
</div>
<div class="figure align-center">
<a class="reference external image-reference" href="../auto_examples/manifold/plot_compare_methods.html"><img alt="modules/../auto_examples/manifold/images/sphx_glr_plot_compare_methods_001.png" src="modules/../auto_examples/manifold/images/sphx_glr_plot_compare_methods_001.png" /></a>
</div>
<p>Manifold learning is an approach to non-linear dimensionality reduction.
Algorithms for this task are based on the idea that the dimensionality of
many data sets is only artificially high.</p>
<div class="section" id="introduction">
<h2>2.2.1. Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>High-dimensional datasets can be very difficult to visualize.  While data
in two or three dimensions can be plotted to show the inherent
structure of the data, equivalent high-dimensional plots are much less
intuitive.  To aid visualization of the structure of a dataset, the
dimension must be reduced in some way.</p>
<p>The simplest way to accomplish this dimensionality reduction is by taking
a random projection of the data.  Though this allows some degree of
visualization of the data structure, the randomness of the choice leaves much
to be desired.  In a random projection, it is likely that the more
interesting structure within the data will be lost.</p>
<p class="centered">
<strong><a class="reference external" href="../auto_examples/manifold/plot_lle_digits.html"><img alt="digits_img" src="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_001.png" /></a> <a class="reference external" href="../auto_examples/manifold/plot_lle_digits.html"><img alt="projected_img" src="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_002.png" /></a></strong></p><p>To address this concern, a number of supervised and unsupervised linear
dimensionality reduction frameworks have been designed, such as Principal
Component Analysis (PCA), Independent Component Analysis, Linear
Discriminant Analysis, and others.  These algorithms define specific
rubrics to choose an “interesting” linear projection of the data.
These methods can be powerful, but often miss important non-linear
structure in the data.</p>
<p class="centered">
<strong><a class="reference external" href="../auto_examples/manifold/plot_lle_digits.html"><img alt="PCA_img" src="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_003.png" /></a> <a class="reference external" href="../auto_examples/manifold/plot_lle_digits.html"><img alt="LDA_img" src="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_004.png" /></a></strong></p><p>Manifold Learning can be thought of as an attempt to generalize linear
frameworks like PCA to be sensitive to non-linear structure in data. Though
supervised variants exist, the typical manifold learning problem is
unsupervised: it learns the high-dimensional structure of the data
from the data itself, without the use of predetermined classifications.</p>
<div class="topic">
<p class="topic-title">Examples:</p>
<ul class="simple">
<li><p>See <a class="reference internal" href="../auto_examples/manifold/plot_lle_digits.html#sphx-glr-auto-examples-manifold-plot-lle-digits-py"><span class="std std-ref">Manifold learning on handwritten digits: Locally Linear Embedding, Isomap…</span></a> for an example of
dimensionality reduction on handwritten digits.</p></li>
<li><p>See <a class="reference internal" href="../auto_examples/manifold/plot_compare_methods.html#sphx-glr-auto-examples-manifold-plot-compare-methods-py"><span class="std std-ref">Comparison of Manifold Learning methods</span></a> for an example of
dimensionality reduction on a toy “S-curve” dataset.</p></li>
</ul>
</div>
<p>The manifold learning implementations available in scikit-learn are
summarized below</p>
</div>
<div class="section" id="isomap">
<span id="id1"></span><h2>2.2.2. Isomap<a class="headerlink" href="#isomap" title="Permalink to this headline">¶</a></h2>
<p>One of the earliest approaches to manifold learning is the Isomap
algorithm, short for Isometric Mapping.  Isomap can be viewed as an
extension of Multi-dimensional Scaling (MDS) or Kernel PCA.
Isomap seeks a lower-dimensional embedding which maintains geodesic
distances between all points.  Isomap can be performed with the object
<a class="reference internal" href="generated/sklearn.manifold.Isomap.html#sklearn.manifold.Isomap" title="sklearn.manifold.Isomap"><code class="xref py py-class docutils literal notranslate"><span class="pre">Isomap</span></code></a>.</p>
<div class="figure align-center">
<a class="reference external image-reference" href="../auto_examples/manifold/plot_lle_digits.html"><img alt="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_005.png" src="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_005.png" /></a>
</div>
<div class="section" id="complexity">
<h3>2.2.2.1. Complexity<a class="headerlink" href="#complexity" title="Permalink to this headline">¶</a></h3>
<p>The Isomap algorithm comprises three stages:</p>
<ol class="arabic simple">
<li><p><strong>Nearest neighbor search.</strong>  Isomap uses
<a class="reference internal" href="generated/sklearn.neighbors.BallTree.html#sklearn.neighbors.BallTree" title="sklearn.neighbors.BallTree"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.neighbors.BallTree</span></code></a> for efficient neighbor search.
The cost is approximately <span class="math notranslate nohighlight">\(O[D \log(k) N \log(N)]\)</span>, for <span class="math notranslate nohighlight">\(k\)</span>
nearest neighbors of <span class="math notranslate nohighlight">\(N\)</span> points in <span class="math notranslate nohighlight">\(D\)</span> dimensions.</p></li>
<li><p><strong>Shortest-path graph search.</strong>  The most efficient known algorithms
for this are <em>Dijkstra’s Algorithm</em>, which is approximately
<span class="math notranslate nohighlight">\(O[N^2(k + \log(N))]\)</span>, or the <em>Floyd-Warshall algorithm</em>, which
is <span class="math notranslate nohighlight">\(O[N^3]\)</span>.  The algorithm can be selected by the user with
the <code class="docutils literal notranslate"><span class="pre">path_method</span></code> keyword of <code class="docutils literal notranslate"><span class="pre">Isomap</span></code>.  If unspecified, the code
attempts to choose the best algorithm for the input data.</p></li>
<li><p><strong>Partial eigenvalue decomposition.</strong>  The embedding is encoded in the
eigenvectors corresponding to the <span class="math notranslate nohighlight">\(d\)</span> largest eigenvalues of the
<span class="math notranslate nohighlight">\(N \times N\)</span> isomap kernel.  For a dense solver, the cost is
approximately <span class="math notranslate nohighlight">\(O[d N^2]\)</span>.  This cost can often be improved using
the <code class="docutils literal notranslate"><span class="pre">ARPACK</span></code> solver.  The eigensolver can be specified by the user
with the <code class="docutils literal notranslate"><span class="pre">path_method</span></code> keyword of <code class="docutils literal notranslate"><span class="pre">Isomap</span></code>.  If unspecified, the
code attempts to choose the best algorithm for the input data.</p></li>
</ol>
<p>The overall complexity of Isomap is
<span class="math notranslate nohighlight">\(O[D \log(k) N \log(N)] + O[N^2(k + \log(N))] + O[d N^2]\)</span>.</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(N\)</span> : number of training data points</p></li>
<li><p><span class="math notranslate nohighlight">\(D\)</span> : input dimension</p></li>
<li><p><span class="math notranslate nohighlight">\(k\)</span> : number of nearest neighbors</p></li>
<li><p><span class="math notranslate nohighlight">\(d\)</span> : output dimension</p></li>
</ul>
<div class="topic">
<p class="topic-title">References:</p>
<ul class="simple">
<li><p><a class="reference external" href="http://science.sciencemag.org/content/290/5500/2319.full">“A global geometric framework for nonlinear dimensionality reduction”</a>
Tenenbaum, J.B.; De Silva, V.; &amp; Langford, J.C.  Science 290 (5500)</p></li>
</ul>
</div>
</div>
</div>
<div class="section" id="locally-linear-embedding">
<span id="id2"></span><h2>2.2.3. Locally Linear Embedding<a class="headerlink" href="#locally-linear-embedding" title="Permalink to this headline">¶</a></h2>
<p>Locally linear embedding (LLE) seeks a lower-dimensional projection of the data
which preserves distances within local neighborhoods.  It can be thought
of as a series of local Principal Component Analyses which are globally
compared to find the best non-linear embedding.</p>
<p>Locally linear embedding can be performed with function
<a class="reference internal" href="generated/sklearn.manifold.locally_linear_embedding.html#sklearn.manifold.locally_linear_embedding" title="sklearn.manifold.locally_linear_embedding"><code class="xref py py-func docutils literal notranslate"><span class="pre">locally_linear_embedding</span></code></a> or its object-oriented counterpart
<a class="reference internal" href="generated/sklearn.manifold.LocallyLinearEmbedding.html#sklearn.manifold.LocallyLinearEmbedding" title="sklearn.manifold.LocallyLinearEmbedding"><code class="xref py py-class docutils literal notranslate"><span class="pre">LocallyLinearEmbedding</span></code></a>.</p>
<div class="figure align-center">
<a class="reference external image-reference" href="../auto_examples/manifold/plot_lle_digits.html"><img alt="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_006.png" src="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_006.png" /></a>
</div>
<div class="section" id="id3">
<h3>2.2.3.1. Complexity<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h3>
<p>The standard LLE algorithm comprises three stages:</p>
<ol class="arabic simple">
<li><p><strong>Nearest Neighbors Search</strong>.  See discussion under Isomap above.</p></li>
<li><p><strong>Weight Matrix Construction</strong>. <span class="math notranslate nohighlight">\(O[D N k^3]\)</span>.
The construction of the LLE weight matrix involves the solution of a
<span class="math notranslate nohighlight">\(k \times k\)</span> linear equation for each of the <span class="math notranslate nohighlight">\(N\)</span> local
neighborhoods</p></li>
<li><p><strong>Partial Eigenvalue Decomposition</strong>. See discussion under Isomap above.</p></li>
</ol>
<p>The overall complexity of standard LLE is
<span class="math notranslate nohighlight">\(O[D \log(k) N \log(N)] + O[D N k^3] + O[d N^2]\)</span>.</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(N\)</span> : number of training data points</p></li>
<li><p><span class="math notranslate nohighlight">\(D\)</span> : input dimension</p></li>
<li><p><span class="math notranslate nohighlight">\(k\)</span> : number of nearest neighbors</p></li>
<li><p><span class="math notranslate nohighlight">\(d\)</span> : output dimension</p></li>
</ul>
<div class="topic">
<p class="topic-title">References:</p>
<ul class="simple">
<li><p><a class="reference external" href="http://www.sciencemag.org/content/290/5500/2323.full">“Nonlinear dimensionality reduction by locally linear embedding”</a>
Roweis, S. &amp; Saul, L.  Science 290:2323 (2000)</p></li>
</ul>
</div>
</div>
</div>
<div class="section" id="modified-locally-linear-embedding">
<h2>2.2.4. Modified Locally Linear Embedding<a class="headerlink" href="#modified-locally-linear-embedding" title="Permalink to this headline">¶</a></h2>
<p>One well-known issue with LLE is the regularization problem.  When the number
of neighbors is greater than the number of input dimensions, the matrix
defining each local neighborhood is rank-deficient.  To address this, standard
LLE applies an arbitrary regularization parameter <span class="math notranslate nohighlight">\(r\)</span>, which is chosen
relative to the trace of the local weight matrix.  Though it can be shown
formally that as <span class="math notranslate nohighlight">\(r \to 0\)</span>, the solution converges to the desired
embedding, there is no guarantee that the optimal solution will be found
for <span class="math notranslate nohighlight">\(r &gt; 0\)</span>.  This problem manifests itself in embeddings which distort
the underlying geometry of the manifold.</p>
<p>One method to address the regularization problem is to use multiple weight
vectors in each neighborhood.  This is the essence of <em>modified locally
linear embedding</em> (MLLE).  MLLE can be  performed with function
<a class="reference internal" href="generated/sklearn.manifold.locally_linear_embedding.html#sklearn.manifold.locally_linear_embedding" title="sklearn.manifold.locally_linear_embedding"><code class="xref py py-func docutils literal notranslate"><span class="pre">locally_linear_embedding</span></code></a> or its object-oriented counterpart
<a class="reference internal" href="generated/sklearn.manifold.LocallyLinearEmbedding.html#sklearn.manifold.LocallyLinearEmbedding" title="sklearn.manifold.LocallyLinearEmbedding"><code class="xref py py-class docutils literal notranslate"><span class="pre">LocallyLinearEmbedding</span></code></a>, with the keyword <code class="docutils literal notranslate"><span class="pre">method</span> <span class="pre">=</span> <span class="pre">'modified'</span></code>.
It requires <code class="docutils literal notranslate"><span class="pre">n_neighbors</span> <span class="pre">&gt;</span> <span class="pre">n_components</span></code>.</p>
<div class="figure align-center">
<a class="reference external image-reference" href="../auto_examples/manifold/plot_lle_digits.html"><img alt="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_007.png" src="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_007.png" /></a>
</div>
<div class="section" id="id4">
<h3>2.2.4.1. Complexity<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h3>
<p>The MLLE algorithm comprises three stages:</p>
<ol class="arabic simple">
<li><p><strong>Nearest Neighbors Search</strong>.  Same as standard LLE</p></li>
<li><p><strong>Weight Matrix Construction</strong>. Approximately
<span class="math notranslate nohighlight">\(O[D N k^3] + O[N (k-D) k^2]\)</span>.  The first term is exactly equivalent
to that of standard LLE.  The second term has to do with constructing the
weight matrix from multiple weights.  In practice, the added cost of
constructing the MLLE weight matrix is relatively small compared to the
cost of stages 1 and 3.</p></li>
<li><p><strong>Partial Eigenvalue Decomposition</strong>. Same as standard LLE</p></li>
</ol>
<p>The overall complexity of MLLE is
<span class="math notranslate nohighlight">\(O[D \log(k) N \log(N)] + O[D N k^3] + O[N (k-D) k^2] + O[d N^2]\)</span>.</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(N\)</span> : number of training data points</p></li>
<li><p><span class="math notranslate nohighlight">\(D\)</span> : input dimension</p></li>
<li><p><span class="math notranslate nohighlight">\(k\)</span> : number of nearest neighbors</p></li>
<li><p><span class="math notranslate nohighlight">\(d\)</span> : output dimension</p></li>
</ul>
<div class="topic">
<p class="topic-title">References:</p>
<ul class="simple">
<li><p><a class="reference external" href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382">“MLLE: Modified Locally Linear Embedding Using Multiple Weights”</a>
Zhang, Z. &amp; Wang, J.</p></li>
</ul>
</div>
</div>
</div>
<div class="section" id="hessian-eigenmapping">
<h2>2.2.5. Hessian Eigenmapping<a class="headerlink" href="#hessian-eigenmapping" title="Permalink to this headline">¶</a></h2>
<p>Hessian Eigenmapping (also known as Hessian-based LLE: HLLE) is another method
of solving the regularization problem of LLE.  It revolves around a
hessian-based quadratic form at each neighborhood which is used to recover
the locally linear structure.  Though other implementations note its poor
scaling with data size, <code class="docutils literal notranslate"><span class="pre">sklearn</span></code> implements some algorithmic
improvements which make its cost comparable to that of other LLE variants
for small output dimension.  HLLE can be  performed with function
<a class="reference internal" href="generated/sklearn.manifold.locally_linear_embedding.html#sklearn.manifold.locally_linear_embedding" title="sklearn.manifold.locally_linear_embedding"><code class="xref py py-func docutils literal notranslate"><span class="pre">locally_linear_embedding</span></code></a> or its object-oriented counterpart
<a class="reference internal" href="generated/sklearn.manifold.LocallyLinearEmbedding.html#sklearn.manifold.LocallyLinearEmbedding" title="sklearn.manifold.LocallyLinearEmbedding"><code class="xref py py-class docutils literal notranslate"><span class="pre">LocallyLinearEmbedding</span></code></a>, with the keyword <code class="docutils literal notranslate"><span class="pre">method</span> <span class="pre">=</span> <span class="pre">'hessian'</span></code>.
It requires <code class="docutils literal notranslate"><span class="pre">n_neighbors</span> <span class="pre">&gt;</span> <span class="pre">n_components</span> <span class="pre">*</span> <span class="pre">(n_components</span> <span class="pre">+</span> <span class="pre">3)</span> <span class="pre">/</span> <span class="pre">2</span></code>.</p>
<div class="figure align-center">
<a class="reference external image-reference" href="../auto_examples/manifold/plot_lle_digits.html"><img alt="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_008.png" src="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_008.png" /></a>
</div>
<div class="section" id="id5">
<h3>2.2.5.1. Complexity<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h3>
<p>The HLLE algorithm comprises three stages:</p>
<ol class="arabic simple">
<li><p><strong>Nearest Neighbors Search</strong>.  Same as standard LLE</p></li>
<li><p><strong>Weight Matrix Construction</strong>. Approximately
<span class="math notranslate nohighlight">\(O[D N k^3] + O[N d^6]\)</span>.  The first term reflects a similar
cost to that of standard LLE.  The second term comes from a QR
decomposition of the local hessian estimator.</p></li>
<li><p><strong>Partial Eigenvalue Decomposition</strong>. Same as standard LLE</p></li>
</ol>
<p>The overall complexity of standard HLLE is
<span class="math notranslate nohighlight">\(O[D \log(k) N \log(N)] + O[D N k^3] + O[N d^6] + O[d N^2]\)</span>.</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(N\)</span> : number of training data points</p></li>
<li><p><span class="math notranslate nohighlight">\(D\)</span> : input dimension</p></li>
<li><p><span class="math notranslate nohighlight">\(k\)</span> : number of nearest neighbors</p></li>
<li><p><span class="math notranslate nohighlight">\(d\)</span> : output dimension</p></li>
</ul>
<div class="topic">
<p class="topic-title">References:</p>
<ul class="simple">
<li><p><a class="reference external" href="http://www.pnas.org/content/100/10/5591">“Hessian Eigenmaps: Locally linear embedding techniques for
high-dimensional data”</a>
Donoho, D. &amp; Grimes, C. Proc Natl Acad Sci USA. 100:5591 (2003)</p></li>
</ul>
</div>
</div>
</div>
<div class="section" id="spectral-embedding">
<span id="id6"></span><h2>2.2.6. Spectral Embedding<a class="headerlink" href="#spectral-embedding" title="Permalink to this headline">¶</a></h2>
<p>Spectral Embedding is an approach to calculating a non-linear embedding.
Scikit-learn implements Laplacian Eigenmaps, which finds a low dimensional
representation of the data using a spectral decomposition of the graph
Laplacian. The graph generated can be considered as a discrete approximation of
the low dimensional manifold in the high dimensional space. Minimization of a
cost function based on the graph ensures that points close to each other on
the manifold are mapped close to each other in the low dimensional space,
preserving local distances. Spectral embedding can be  performed with the
function <a class="reference internal" href="generated/sklearn.manifold.spectral_embedding.html#sklearn.manifold.spectral_embedding" title="sklearn.manifold.spectral_embedding"><code class="xref py py-func docutils literal notranslate"><span class="pre">spectral_embedding</span></code></a> or its object-oriented counterpart
<a class="reference internal" href="generated/sklearn.manifold.SpectralEmbedding.html#sklearn.manifold.SpectralEmbedding" title="sklearn.manifold.SpectralEmbedding"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpectralEmbedding</span></code></a>.</p>
<div class="section" id="id7">
<h3>2.2.6.1. Complexity<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h3>
<p>The Spectral Embedding (Laplacian Eigenmaps) algorithm comprises three stages:</p>
<ol class="arabic simple">
<li><p><strong>Weighted Graph Construction</strong>. Transform the raw input data into
graph representation using affinity (adjacency) matrix representation.</p></li>
<li><p><strong>Graph Laplacian Construction</strong>. unnormalized Graph Laplacian
is constructed as <span class="math notranslate nohighlight">\(L = D - A\)</span> for and normalized one as
<span class="math notranslate nohighlight">\(L = D^{-\frac{1}{2}} (D - A) D^{-\frac{1}{2}}\)</span>.</p></li>
<li><p><strong>Partial Eigenvalue Decomposition</strong>. Eigenvalue decomposition is
done on graph Laplacian</p></li>
</ol>
<p>The overall complexity of spectral embedding is
<span class="math notranslate nohighlight">\(O[D \log(k) N \log(N)] + O[D N k^3] + O[d N^2]\)</span>.</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(N\)</span> : number of training data points</p></li>
<li><p><span class="math notranslate nohighlight">\(D\)</span> : input dimension</p></li>
<li><p><span class="math notranslate nohighlight">\(k\)</span> : number of nearest neighbors</p></li>
<li><p><span class="math notranslate nohighlight">\(d\)</span> : output dimension</p></li>
</ul>
<div class="topic">
<p class="topic-title">References:</p>
<ul class="simple">
<li><p><a class="reference external" href="https://web.cse.ohio-state.edu/~mbelkin/papers/LEM_NC_03.pdf">“Laplacian Eigenmaps for Dimensionality Reduction
and Data Representation”</a>
M. Belkin, P. Niyogi, Neural Computation, June 2003; 15 (6):1373-1396</p></li>
</ul>
</div>
</div>
</div>
<div class="section" id="local-tangent-space-alignment">
<h2>2.2.7. Local Tangent Space Alignment<a class="headerlink" href="#local-tangent-space-alignment" title="Permalink to this headline">¶</a></h2>
<p>Though not technically a variant of LLE, Local tangent space alignment (LTSA)
is algorithmically similar enough to LLE that it can be put in this category.
Rather than focusing on preserving neighborhood distances as in LLE, LTSA
seeks to characterize the local geometry at each neighborhood via its
tangent space, and performs a global optimization to align these local
tangent spaces to learn the embedding.  LTSA can be performed with function
<a class="reference internal" href="generated/sklearn.manifold.locally_linear_embedding.html#sklearn.manifold.locally_linear_embedding" title="sklearn.manifold.locally_linear_embedding"><code class="xref py py-func docutils literal notranslate"><span class="pre">locally_linear_embedding</span></code></a> or its object-oriented counterpart
<a class="reference internal" href="generated/sklearn.manifold.LocallyLinearEmbedding.html#sklearn.manifold.LocallyLinearEmbedding" title="sklearn.manifold.LocallyLinearEmbedding"><code class="xref py py-class docutils literal notranslate"><span class="pre">LocallyLinearEmbedding</span></code></a>, with the keyword <code class="docutils literal notranslate"><span class="pre">method</span> <span class="pre">=</span> <span class="pre">'ltsa'</span></code>.</p>
<div class="figure align-center">
<a class="reference external image-reference" href="../auto_examples/manifold/plot_lle_digits.html"><img alt="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_009.png" src="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_009.png" /></a>
</div>
<div class="section" id="id8">
<h3>2.2.7.1. Complexity<a class="headerlink" href="#id8" title="Permalink to this headline">¶</a></h3>
<p>The LTSA algorithm comprises three stages:</p>
<ol class="arabic simple">
<li><p><strong>Nearest Neighbors Search</strong>.  Same as standard LLE</p></li>
<li><p><strong>Weight Matrix Construction</strong>. Approximately
<span class="math notranslate nohighlight">\(O[D N k^3] + O[k^2 d]\)</span>.  The first term reflects a similar
cost to that of standard LLE.</p></li>
<li><p><strong>Partial Eigenvalue Decomposition</strong>. Same as standard LLE</p></li>
</ol>
<p>The overall complexity of standard LTSA is
<span class="math notranslate nohighlight">\(O[D \log(k) N \log(N)] + O[D N k^3] + O[k^2 d] + O[d N^2]\)</span>.</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(N\)</span> : number of training data points</p></li>
<li><p><span class="math notranslate nohighlight">\(D\)</span> : input dimension</p></li>
<li><p><span class="math notranslate nohighlight">\(k\)</span> : number of nearest neighbors</p></li>
<li><p><span class="math notranslate nohighlight">\(d\)</span> : output dimension</p></li>
</ul>
<div class="topic">
<p class="topic-title">References:</p>
<ul class="simple">
<li><p><a class="reference external" href="http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.3693">“Principal manifolds and nonlinear dimensionality reduction via
tangent space alignment”</a>
Zhang, Z. &amp; Zha, H. Journal of Shanghai Univ. 8:406 (2004)</p></li>
</ul>
</div>
</div>
</div>
<div class="section" id="multi-dimensional-scaling-mds">
<span id="multidimensional-scaling"></span><h2>2.2.8. Multi-dimensional Scaling (MDS)<a class="headerlink" href="#multi-dimensional-scaling-mds" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="https://en.wikipedia.org/wiki/Multidimensional_scaling">Multidimensional scaling</a>
(<a class="reference internal" href="generated/sklearn.manifold.MDS.html#sklearn.manifold.MDS" title="sklearn.manifold.MDS"><code class="xref py py-class docutils literal notranslate"><span class="pre">MDS</span></code></a>) seeks a low-dimensional
representation of the data in which the distances respect well the
distances in the original high-dimensional space.</p>
<p>In general, <a class="reference internal" href="generated/sklearn.manifold.MDS.html#sklearn.manifold.MDS" title="sklearn.manifold.MDS"><code class="xref py py-class docutils literal notranslate"><span class="pre">MDS</span></code></a> is a technique used for analyzing similarity or
dissimilarity data. It attempts to model similarity or dissimilarity data as
distances in a geometric spaces. The data can be ratings of similarity between
objects, interaction frequencies of molecules, or trade indices between
countries.</p>
<p>There exists two types of MDS algorithm: metric and non metric. In the
scikit-learn, the class <a class="reference internal" href="generated/sklearn.manifold.MDS.html#sklearn.manifold.MDS" title="sklearn.manifold.MDS"><code class="xref py py-class docutils literal notranslate"><span class="pre">MDS</span></code></a> implements both. In Metric MDS, the input
similarity matrix arises from a metric (and thus respects the triangular
inequality), the distances between output two points are then set to be as
close as possible to the similarity or dissimilarity data. In the non-metric
version, the algorithms will try to preserve the order of the distances, and
hence seek for a monotonic relationship between the distances in the embedded
space and the similarities/dissimilarities.</p>
<div class="figure align-center">
<a class="reference external image-reference" href="../auto_examples/manifold/plot_lle_digits.html"><img alt="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_010.png" src="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_010.png" /></a>
</div>
<p>Let <span class="math notranslate nohighlight">\(S\)</span> be the similarity matrix, and <span class="math notranslate nohighlight">\(X\)</span> the coordinates of the
<span class="math notranslate nohighlight">\(n\)</span> input points. Disparities <span class="math notranslate nohighlight">\(\hat{d}_{ij}\)</span> are transformation of
the similarities chosen in some optimal ways. The objective, called the
stress, is then defined by <span class="math notranslate nohighlight">\(\sum_{i &lt; j} d_{ij}(X) - \hat{d}_{ij}(X)\)</span></p>
<div class="section" id="metric-mds">
<h3>2.2.8.1. Metric MDS<a class="headerlink" href="#metric-mds" title="Permalink to this headline">¶</a></h3>
<p>The simplest metric <a class="reference internal" href="generated/sklearn.manifold.MDS.html#sklearn.manifold.MDS" title="sklearn.manifold.MDS"><code class="xref py py-class docutils literal notranslate"><span class="pre">MDS</span></code></a> model, called <em>absolute MDS</em>, disparities are defined by
<span class="math notranslate nohighlight">\(\hat{d}_{ij} = S_{ij}\)</span>. With absolute MDS, the value <span class="math notranslate nohighlight">\(S_{ij}\)</span>
should then correspond exactly to the distance between point <span class="math notranslate nohighlight">\(i\)</span> and
<span class="math notranslate nohighlight">\(j\)</span> in the embedding point.</p>
<p>Most commonly, disparities are set to <span class="math notranslate nohighlight">\(\hat{d}_{ij} = b S_{ij}\)</span>.</p>
</div>
<div class="section" id="nonmetric-mds">
<h3>2.2.8.2. Nonmetric MDS<a class="headerlink" href="#nonmetric-mds" title="Permalink to this headline">¶</a></h3>
<p>Non metric <a class="reference internal" href="generated/sklearn.manifold.MDS.html#sklearn.manifold.MDS" title="sklearn.manifold.MDS"><code class="xref py py-class docutils literal notranslate"><span class="pre">MDS</span></code></a> focuses on the ordination of the data. If
<span class="math notranslate nohighlight">\(S_{ij} &lt; S_{jk}\)</span>, then the embedding should enforce <span class="math notranslate nohighlight">\(d_{ij} &lt;
d_{jk}\)</span>. A simple algorithm to enforce that is to use a monotonic regression
of <span class="math notranslate nohighlight">\(d_{ij}\)</span> on <span class="math notranslate nohighlight">\(S_{ij}\)</span>, yielding disparities <span class="math notranslate nohighlight">\(\hat{d}_{ij}\)</span>
in the same order as <span class="math notranslate nohighlight">\(S_{ij}\)</span>.</p>
<p>A trivial solution to this problem is to set all the points on the origin. In
order to avoid that, the disparities <span class="math notranslate nohighlight">\(\hat{d}_{ij}\)</span> are normalized.</p>
<div class="figure align-center">
<a class="reference external image-reference" href="../auto_examples/manifold/plot_mds.html"><img alt="modules/../auto_examples/manifold/images/sphx_glr_plot_mds_001.png" src="modules/../auto_examples/manifold/images/sphx_glr_plot_mds_001.png" /></a>
</div>
<div class="topic">
<p class="topic-title">References:</p>
<ul class="simple">
<li><p><a class="reference external" href="https://www.springer.com/fr/book/9780387251509">“Modern Multidimensional Scaling - Theory and Applications”</a>
Borg, I.; Groenen P. Springer Series in Statistics (1997)</p></li>
<li><p><a class="reference external" href="https://link.springer.com/article/10.1007%2FBF02289694">“Nonmetric multidimensional scaling: a numerical method”</a>
Kruskal, J. Psychometrika, 29 (1964)</p></li>
<li><p><a class="reference external" href="https://link.springer.com/article/10.1007%2FBF02289565">“Multidimensional scaling by optimizing goodness of fit to a nonmetric hypothesis”</a>
Kruskal, J. Psychometrika, 29, (1964)</p></li>
</ul>
</div>
</div>
</div>
<div class="section" id="t-distributed-stochastic-neighbor-embedding-t-sne">
<span id="t-sne"></span><h2>2.2.9. t-distributed Stochastic Neighbor Embedding (t-SNE)<a class="headerlink" href="#t-distributed-stochastic-neighbor-embedding-t-sne" title="Permalink to this headline">¶</a></h2>
<p>t-SNE (<a class="reference internal" href="generated/sklearn.manifold.TSNE.html#sklearn.manifold.TSNE" title="sklearn.manifold.TSNE"><code class="xref py py-class docutils literal notranslate"><span class="pre">TSNE</span></code></a>) converts affinities of data points to probabilities.
The affinities in the original space are represented by Gaussian joint
probabilities and the affinities in the embedded space are represented by
Student’s t-distributions. This allows t-SNE to be particularly sensitive
to local structure and has a few other advantages over existing techniques:</p>
<ul class="simple">
<li><p>Revealing the structure at many scales on a single map</p></li>
<li><p>Revealing data that lie in multiple, different, manifolds or clusters</p></li>
<li><p>Reducing the tendency to crowd points together at the center</p></li>
</ul>
<p>While Isomap, LLE and variants are best suited to unfold a single continuous
low dimensional manifold, t-SNE will focus on the local structure of the data
and will tend to extract clustered local groups of samples as highlighted on
the S-curve example. This ability to group samples based on the local structure
might be beneficial to visually disentangle a dataset that comprises several
manifolds at once as is the case in the digits dataset.</p>
<p>The Kullback-Leibler (KL) divergence of the joint
probabilities in the original space and the embedded space will be minimized
by gradient descent. Note that the KL divergence is not convex, i.e.
multiple restarts with different initializations will end up in local minima
of the KL divergence. Hence, it is sometimes useful to try different seeds
and select the embedding with the lowest KL divergence.</p>
<p>The disadvantages to using t-SNE are roughly:</p>
<ul class="simple">
<li><p>t-SNE is computationally expensive, and can take several hours on million-sample
datasets where PCA will finish in seconds or minutes</p></li>
<li><p>The Barnes-Hut t-SNE method is limited to two or three dimensional embeddings.</p></li>
<li><p>The algorithm is stochastic and multiple restarts with different seeds can
yield different embeddings. However, it is perfectly legitimate to pick the
embedding with the least error.</p></li>
<li><p>Global structure is not explicitly preserved. This problem is mitigated by
initializing points with PCA (using <code class="docutils literal notranslate"><span class="pre">init='pca'</span></code>).</p></li>
</ul>
<div class="figure align-center">
<a class="reference external image-reference" href="../auto_examples/manifold/plot_lle_digits.html"><img alt="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_013.png" src="modules/../auto_examples/manifold/images/sphx_glr_plot_lle_digits_013.png" /></a>
</div>
<div class="section" id="optimizing-t-sne">
<h3>2.2.9.1. Optimizing t-SNE<a class="headerlink" href="#optimizing-t-sne" title="Permalink to this headline">¶</a></h3>
<p>The main purpose of t-SNE is visualization of high-dimensional data. Hence,
it works best when the data will be embedded on two or three dimensions.</p>
<p>Optimizing the KL divergence can be a little bit tricky sometimes. There are
five parameters that control the optimization of t-SNE and therefore possibly
the quality of the resulting embedding:</p>
<ul class="simple">
<li><p>perplexity</p></li>
<li><p>early exaggeration factor</p></li>
<li><p>learning rate</p></li>
<li><p>maximum number of iterations</p></li>
<li><p>angle (not used in the exact method)</p></li>
</ul>
<p>The perplexity is defined as <span class="math notranslate nohighlight">\(k=2^{(S)}\)</span> where <span class="math notranslate nohighlight">\(S\)</span> is the Shannon
entropy of the conditional probability distribution. The perplexity of a
<span class="math notranslate nohighlight">\(k\)</span>-sided die is <span class="math notranslate nohighlight">\(k\)</span>, so that <span class="math notranslate nohighlight">\(k\)</span> is effectively the number of
nearest neighbors t-SNE considers when generating the conditional probabilities.
Larger perplexities lead to more nearest neighbors and less sensitive to small
structure. Conversely a lower perplexity considers a smaller number of
neighbors, and thus ignores more global information in favour of the
local neighborhood. As dataset sizes get larger more points will be
required to get a reasonable sample of the local neighborhood, and hence
larger perplexities may be required. Similarly noisier datasets will require
larger perplexity values to encompass enough local neighbors to see beyond
the background noise.</p>
<p>The maximum number of iterations is usually high enough and does not need
any tuning. The optimization consists of two phases: the early exaggeration
phase and the final optimization. During early exaggeration the joint
probabilities in the original space will be artificially increased by
multiplication with a given factor. Larger factors result in larger gaps
between natural clusters in the data. If the factor is too high, the KL
divergence could increase during this phase. Usually it does not have to be
tuned. A critical parameter is the learning rate. If it is too low gradient
descent will get stuck in a bad local minimum. If it is too high the KL
divergence will increase during optimization. More tips can be found in
Laurens van der Maaten’s FAQ (see references). The last parameter, angle,
is a tradeoff between performance and accuracy. Larger angles imply that we
can approximate larger regions by a single point, leading to better speed
but less accurate results.</p>
<p><a class="reference external" href="https://distill.pub/2016/misread-tsne/">“How to Use t-SNE Effectively”</a>
provides a good discussion of the effects of the various parameters, as well
as interactive plots to explore the effects of different parameters.</p>
</div>
<div class="section" id="barnes-hut-t-sne">
<h3>2.2.9.2. Barnes-Hut t-SNE<a class="headerlink" href="#barnes-hut-t-sne" title="Permalink to this headline">¶</a></h3>
<p>The Barnes-Hut t-SNE that has been implemented here is usually much slower than
other manifold learning algorithms. The optimization is quite difficult
and the computation of the gradient is <span class="math notranslate nohighlight">\(O[d N log(N)]\)</span>, where <span class="math notranslate nohighlight">\(d\)</span>
is the number of output dimensions and <span class="math notranslate nohighlight">\(N\)</span> is the number of samples. The
Barnes-Hut method improves on the exact method where t-SNE complexity is
<span class="math notranslate nohighlight">\(O[d N^2]\)</span>, but has several other notable differences:</p>
<ul class="simple">
<li><p>The Barnes-Hut implementation only works when the target dimensionality is 3
or less. The 2D case is typical when building visualizations.</p></li>
<li><p>Barnes-Hut only works with dense input data. Sparse data matrices can only be
embedded with the exact method or can be approximated by a dense low rank
projection for instance using <a class="reference internal" href="generated/sklearn.decomposition.TruncatedSVD.html#sklearn.decomposition.TruncatedSVD" title="sklearn.decomposition.TruncatedSVD"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.decomposition.TruncatedSVD</span></code></a></p></li>
<li><p>Barnes-Hut is an approximation of the exact method. The approximation is
parameterized with the angle parameter, therefore the angle parameter is
unused when method=”exact”</p></li>
<li><p>Barnes-Hut is significantly more scalable. Barnes-Hut can be used to embed
hundred of thousands of data points while the exact method can handle
thousands of samples before becoming computationally intractable</p></li>
</ul>
<p>For visualization purpose (which is the main use case of t-SNE), using the
Barnes-Hut method is strongly recommended. The exact t-SNE method is useful
for checking the theoretically properties of the embedding possibly in higher
dimensional space but limit to small datasets due to computational constraints.</p>
<p>Also note that the digits labels roughly match the natural grouping found by
t-SNE while the linear 2D projection of the PCA model yields a representation
where label regions largely overlap. This is a strong clue that this data can
be well separated by non linear methods that focus on the local structure (e.g.
an SVM with a Gaussian RBF kernel). However, failing to visualize well
separated homogeneously labeled groups with t-SNE in 2D does not necessarily
imply that the data cannot be correctly classified by a supervised model. It
might be the case that 2 dimensions are not low enough to accurately represents
the internal structure of the data.</p>
<div class="topic">
<p class="topic-title">References:</p>
<ul class="simple">
<li><p><a class="reference external" href="http://jmlr.org/papers/v9/vandermaaten08a.html">“Visualizing High-Dimensional Data Using t-SNE”</a>
van der Maaten, L.J.P.; Hinton, G. Journal of Machine Learning Research
(2008)</p></li>
<li><p><a class="reference external" href="https://lvdmaaten.github.io/tsne/">“t-Distributed Stochastic Neighbor Embedding”</a>
van der Maaten, L.J.P.</p></li>
<li><p><a class="reference external" href="https://lvdmaaten.github.io/publications/papers/JMLR_2014.pdf">“Accelerating t-SNE using Tree-Based Algorithms.”</a>
L.J.P. van der Maaten.  Journal of Machine Learning Research 15(Oct):3221-3245, 2014.</p></li>
</ul>
</div>
</div>
</div>
<div class="section" id="tips-on-practical-use">
<h2>2.2.10. Tips on practical use<a class="headerlink" href="#tips-on-practical-use" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><p>Make sure the same scale is used over all features. Because manifold
learning methods are based on a nearest-neighbor search, the algorithm
may perform poorly otherwise.  See <a class="reference internal" href="preprocessing.html#preprocessing-scaler"><span class="std std-ref">StandardScaler</span></a>
for convenient ways of scaling heterogeneous data.</p></li>
<li><p>The reconstruction error computed by each routine can be used to choose
the optimal output dimension.  For a <span class="math notranslate nohighlight">\(d\)</span>-dimensional manifold embedded
in a <span class="math notranslate nohighlight">\(D\)</span>-dimensional parameter space, the reconstruction error will
decrease as <code class="docutils literal notranslate"><span class="pre">n_components</span></code> is increased until <code class="docutils literal notranslate"><span class="pre">n_components</span> <span class="pre">==</span> <span class="pre">d</span></code>.</p></li>
<li><p>Note that noisy data can “short-circuit” the manifold, in essence acting
as a bridge between parts of the manifold that would otherwise be
well-separated.  Manifold learning on noisy and/or incomplete data is
an active area of research.</p></li>
<li><p>Certain input configurations can lead to singular weight matrices, for
example when more than two points in the dataset are identical, or when
the data is split into disjointed groups.  In this case, <code class="docutils literal notranslate"><span class="pre">solver='arpack'</span></code>
will fail to find the null space.  The easiest way to address this is to
use <code class="docutils literal notranslate"><span class="pre">solver='dense'</span></code> which will work on a singular matrix, though it may
be very slow depending on the number of input points.  Alternatively, one
can attempt to understand the source of the singularity: if it is due to
disjoint sets, increasing <code class="docutils literal notranslate"><span class="pre">n_neighbors</span></code> may help.  If it is due to
identical points in the dataset, removing these points may help.</p></li>
</ul>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="ensemble.html#random-trees-embedding"><span class="std std-ref">Totally Random Trees Embedding</span></a> can also be useful to derive non-linear
representations of feature space, also it does not perform
dimensionality reduction.</p>
</div>
</div>
</div>


      </div>
    <div class="container">
      <footer class="sk-content-footer">
            &copy; 2007 - 2019, scikit-learn developers (BSD License).
          <a href="../_sources/modules/manifold.rst.txt" rel="nofollow">Show this page source</a>
      </footer>
    </div>
  </div>
</div>
<script src="../_static/js/vendor/bootstrap.min.js"></script>

<script>
    window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
    ga('create', 'UA-22606712-2', 'auto');
    ga('set', 'anonymizeIp', true);
    ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>


<script>
$(document).ready(function() {
    /* Add a [>>>] button on the top-right corner of code samples to hide
     * the >>> and ... prompts and the output and thus make the code
     * copyable. */
    var div = $('.highlight-python .highlight,' +
                '.highlight-python3 .highlight,' +
                '.highlight-pycon .highlight,' +
		'.highlight-default .highlight')
    var pre = div.find('pre');

    // get the styles from the current theme
    pre.parent().parent().css('position', 'relative');
    var hide_text = 'Hide prompts and outputs';
    var show_text = 'Show prompts and outputs';

    // create and add the button to all the code blocks that contain >>>
    div.each(function(index) {
        var jthis = $(this);
        if (jthis.find('.gp').length > 0) {
            var button = $('<span class="copybutton">&gt;&gt;&gt;</span>');
            button.attr('title', hide_text);
            button.data('hidden', 'false');
            jthis.prepend(button);
        }
        // tracebacks (.gt) contain bare text elements that need to be
        // wrapped in a span to work with .nextUntil() (see later)
        jthis.find('pre:has(.gt)').contents().filter(function() {
            return ((this.nodeType == 3) && (this.data.trim().length > 0));
        }).wrap('<span>');
    });

    // define the behavior of the button when it's clicked
    $('.copybutton').click(function(e){
        e.preventDefault();
        var button = $(this);
        if (button.data('hidden') === 'false') {
            // hide the code output
            button.parent().find('.go, .gp, .gt').hide();
            button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden');
            button.css('text-decoration', 'line-through');
            button.attr('title', show_text);
            button.data('hidden', 'true');
        } else {
            // show the code output
            button.parent().find('.go, .gp, .gt').show();
            button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible');
            button.css('text-decoration', 'none');
            button.attr('title', hide_text);
            button.data('hidden', 'false');
        }
    });

	/*** Add permalink buttons next to glossary terms ***/
	$('dl.glossary > dt[id]').append(function() {
		return ('<a class="headerlink" href="#' +
			    this.getAttribute('id') +
			    '" title="Permalink to this term">¶</a>');
	});
  /*** Hide navbar when scrolling down ***/
  // Returns true when headerlink target matches hash in url
  (function() {
    hashTargetOnTop = function() {
        var hash = window.location.hash;
        if ( hash.length < 2 ) { return false; }

        var target = document.getElementById( hash.slice(1) );
        if ( target === null ) { return false; }

        var top = target.getBoundingClientRect().top;
        return (top < 2) && (top > -2);
    };

    // Hide navbar on load if hash target is on top
    var navBar = document.getElementById("navbar");
    var navBarToggler = document.getElementById("sk-navbar-toggler");
    var navBarHeightHidden = "-" + navBar.getBoundingClientRect().height + "px";
    var $window = $(window);

    hideNavBar = function() {
        navBar.style.top = navBarHeightHidden;
    };

    showNavBar = function() {
        navBar.style.top = "0";
    }

    if (hashTargetOnTop()) {
        hideNavBar()
    }

    var prevScrollpos = window.pageYOffset;
    hideOnScroll = function(lastScrollTop) {
        if (($window.width() < 768) && (navBarToggler.getAttribute("aria-expanded") === 'true')) {
            return;
        }
        if (lastScrollTop > 2 && (prevScrollpos <= lastScrollTop) || hashTargetOnTop()){
            hideNavBar()
        } else {
            showNavBar()
        }
        prevScrollpos = lastScrollTop;
    };

    /*** high preformance scroll event listener***/
    var raf = window.requestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        window.oRequestAnimationFrame;
    var lastScrollTop = $window.scrollTop();

    if (raf) {
        loop();
    }

    function loop() {
        var scrollTop = $window.scrollTop();
        if (lastScrollTop === scrollTop) {
            raf(loop);
            return;
        } else {
            lastScrollTop = scrollTop;
            hideOnScroll(lastScrollTop);
            raf(loop);
        }
    }
  })();
});

</script>
    
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
    
</body>
</html>